package br.ufla.pgcc.oomeasures.astvisitors;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.ImportDeclaration;

public class ImportCouplingVisitor extends ASTVisitor{
	
	private List<ImportDeclaration> listOfImports = new ArrayList<ImportDeclaration>();

	@Override
	public boolean visit(CompilationUnit unit) {
		
		calculateNumberOfImportsOfClass(unit);
		
		return super.visit(unit);
	}
	
	@SuppressWarnings("unchecked")
	private void calculateNumberOfImportsOfClass(CompilationUnit unit){
		listOfImports = unit.imports();
	}
	
	public int getImportCouplingIndex(){
		
		if (!listOfImports.isEmpty())
			return listOfImports.size();
		
		return 0;
	}
}
